package product.Dao.impl;

import product.Dao.productDao;
import product.bean.Product;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import util.JdbcUtil;

/**
 * Created by Administrator on 2018/11/28.
 */
public class productDaoimpl implements productDao {
    @Override
    public List<Product> getBookList() {
        Connection collection=null;
        PreparedStatement ps=null;
        ResultSet resultSet=null;
        List<Product>products=new ArrayList<Product>();
        try {
            collection=JdbcUtil.getConnertion();
            String sql="select productId,productname,price,auther,productimgurl from product where productState='5'";
            ps=collection.prepareStatement(sql);
            resultSet=ps.executeQuery();
            while (resultSet.next()){
                Product product=new Product();
                product.setId(resultSet.getInt("productId"));
                product.setProductname(resultSet.getString("productname"));
                product.setPrice(resultSet.getDouble("price"));
                product.setAuther(resultSet.getString("auther"));
                product.setImgurl(resultSet.getString("productimgurl"));
                products.add(product);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUtil.close(collection,ps,resultSet);
        }
        return products;
    }
}
